﻿//-----------------------------------------------------------------------
// <copyright file="AppDomainDataContractUnitTest.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Contracts
{
    using System;

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    /// <summary>
    /// Provides unit tests for the <see cref="T:CodePlex.Diagnostics.Contracts.AppDomainDataContract"/> class.
    /// </summary>
    [TestClass]
    public sealed class AppDomainDataContractUnitTest
    {
        #region public AppDomainDataContractUnitTest()

        /// <summary>
        /// Initializes a new instance of the <see cref="T:AppDomainDataContractUnitTest"/> class.
        /// </summary>
        public AppDomainDataContractUnitTest()
        {
        }

        #endregion

        #region public TestContext TestContext

        /// <summary>
        /// Gets or sets the test context which provides information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get;
            set;
        }

        #endregion

        #region public void AppDomainDataContractConstructorUnitTest()

        /// <summary>
        /// Ensures that the constructor of the <see cref="T:CodePlex.Diagnostics.Contracts.AppDomainDataContract"/> class is correctly copying the values from the supplied <see cref="T:System.AppDomain"/> instance.
        /// </summary>
        [TestMethod]
        public void AppDomainDataContractConstructorUnitTest()
        {
            AppDomainDataContract appDomain = new AppDomainDataContract(AppDomain.CurrentDomain);

            Assert.AreEqual<string>(AppDomain.CurrentDomain.BaseDirectory, appDomain.BaseDirectory, "data contract contains an invalid base directory value.");
            
            if (AppDomain.CurrentDomain.DomainManager != null)
            {
                Assert.AreEqual<string>(AppDomain.CurrentDomain.DomainManager.ToString(), appDomain.DomainManager, "data contract contains an invalid domain manager value.");
            }
            else
            {
                Assert.IsNull(appDomain.DomainManager, "application domain does not have a reference to a domain manager, the data contract domain manager should be null value.");            
            }

            Assert.AreEqual<string>(AppDomain.CurrentDomain.DynamicDirectory, appDomain.DynamicDirectory, "data contract contains an invalid dyanamic directory value.");
            Assert.AreEqual<string>(AppDomain.CurrentDomain.FriendlyName, appDomain.FriendlyName, "data contract contains an invalid friendly name value.");
            Assert.AreEqual<int?>(AppDomain.CurrentDomain.Id, appDomain.Id, "data contract contains an invalid Id value.");
            Assert.AreEqual<string>(AppDomain.CurrentDomain.RelativeSearchPath, appDomain.RelativeSearchPath, "data contract contains an invalid relative search path value.");
        }
        
        #endregion
   }
}
